//
//  YKStatues.m
//  youkan
//
//  Created by mac mini on 16/2/29.
//  Copyright © 2016年 Honsintech. All rights reserved.
//

#import "YKWBStatues.h"
#import "YKPhoto.h"
#import "NSDate+MJ.h"
#import "YKUser.h"
@implementation YKStatusTitle
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"baseColor" : @"base_color",
             @"iconURL" : @"icon_url"};
}
@end

@implementation YKWBStatues
+ (NSDictionary *)objectClassInArray{
//自动把数组中的字典转成对应的模型
    return @{@"pic_urls":[YKPhoto class]};
}
-(NSString *)created_at{
   //Thu Mar 03 22:54:12 +0800 2016

    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"EEE MMM d HH:mm:ss Z yyyy";
    fmt.locale =[[NSLocale alloc]initWithLocaleIdentifier:@"en"];
    NSDate *created_at = [fmt dateFromString:_created_at];
//        YKLog(@"time==%@",created_at);
    if ([created_at isThisYear]) {
        if ([created_at isToday]) {
            NSDateComponents *cmp =[created_at deltaWithNow];
            if (cmp.hour>=1) {
                return [NSString stringWithFormat:@"%ld小时前",cmp.hour];
            }else if(cmp.minute>1){
                return [NSString stringWithFormat:@"%ld分钟前",cmp.minute];
            }else{
                return @"刚刚";
            }
        }else if([created_at isYesterday]){
            fmt.dateFormat =@"昨天 HH:mm";
            return [fmt stringFromDate:created_at];
        }else{
            fmt.dateFormat =@"MM-dd HH:mm";
            return [fmt stringFromDate:created_at];
        }
    }else{
        fmt.dateFormat =@"yyyy-MM-dd";
        return [fmt stringFromDate:created_at];
    }
    return _created_at;
}
-(void)setSource:(NSString *)source{
//    YKLog(@"%@",source);
//    <a href="http://app.weibo.com/t/feed/3o33sO" rel="nofollow">iPhone 6</a>
    NSRange range=[source rangeOfString:@">"];
    source =[source substringFromIndex:range.location+range.length];
    range =[source rangeOfString:@"<"];
    source =[source substringToIndex:range.location];
    source =[NSString stringWithFormat:@"来自%@",source];
//        YKLog(@"%@",source);
    _source =source;
}
-(void)setRetweeted_status:(YKWBStatues *)retweeted_status{
    _retweeted_status =retweeted_status;
    _retweetName =[NSString stringWithFormat:@"@%@",retweeted_status.user.name];
}
//picBg
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{ @"picBg" : @"pic_bg",
              @"sourceAllowClick" : @"source_allowclick",
              };
}
@end


@implementation WBEmoticon
+ (NSArray *)modelPropertyBlacklist {
    return @[@"group"];
}
@end

@implementation WBEmoticonGroup
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"groupID" : @"id",
             @"nameCN" : @"group_name_cn",
             @"nameEN" : @"group_name_en",
             @"nameTW" : @"group_name_tw",
             @"displayOnly" : @"display_only",
             @"groupType" : @"group_type"};
}
+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{@"emoticons" : [WBEmoticon class]};
}
- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
    [_emoticons enumerateObjectsUsingBlock:^(WBEmoticon *emoticon, NSUInteger idx, BOOL *stop) {
        emoticon.group = self;
    }];
    return YES;
}
@end
